var express = require('express');
var router = express.Router();

var path = require('path');
var bodyparser = require('body-parser');
var pathViews = __dirname.substring(0,__dirname.lastIndexOf('\\')) + '\\views\\';

router.use(bodyparser.urlencoded({extended: false}));

/* GET home page. */
router.get('/', function(req, res, next) {
  console.log(pathViews);
  res.render('index', { title: 'Express' });
});

router.get('/login',(req,res)=>{
  res.sendFile(pathViews + 'login.html');
});

router.post('/login',(req,res)=>{
  console.log(req.body);
  var user = req.body.username;
  var pass = req.body.password;
  if(user === 'admin'&& pass === '123456'){
    res.send('<h1>登录成功！</h1>');
  }else{
    res.send('<h1>登录失败！</h1>');
  }

});

module.exports = router;
